package com.ruoyi.huanghefd.controller;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONWriter;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.huanghefd.domain.HighWorkApproveSheet;
import com.ruoyi.huanghefd.service.HighWorkApproveSheetService;
import com.ruoyi.huanghefd.utils.PageBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @Author gnplum
 * @Date 2024/12/4 17:55
 * @PackageName:com.ruoyi.huanghefd.controller
 * @ClassName: HighWorkApproveSheetController
 * @Description: TODO
 * @Version 1.0
 */
@RestController
@RequestMapping("/huanghefd")
public class HighWorkApproveSheetController {
    private static final Logger log = LoggerFactory.getLogger(HighWorkApproveSheetController.class);
    @Resource
    private HighWorkApproveSheetService highWorkApproveSheetService;

    @PostMapping("/addHighWorkApproveSheet")
    public AjaxResult addHighWorkApproveSheet(@RequestBody HighWorkApproveSheet highWorkApproveSheet) {
        log.info(">> 新增高空作业审批单-入参==" + JSON.toJSONString(highWorkApproveSheet));
        AjaxResult ajax = highWorkApproveSheetService.addHighWorkApproveSheet(highWorkApproveSheet);
        log.info("<< 新增高空作业审批单-返回==" + ajax.toString());
        return ajax;
    }

    @PostMapping("/delHighWorkApproveSheet")
    public AjaxResult delHighWorkApproveSheet(@RequestParam(required = false, value = "hsCode") String hsCode) {
        log.info(">> 删除高空作业审批单-入参 hsCode==" + hsCode);
        if (hsCode.isEmpty()) {
            return AjaxResult.success("请点选要删除的工作票");
        }
        AjaxResult ajax = highWorkApproveSheetService.delHighWorkApproveSheet(hsCode);
        log.info(">> 删除高空作业审批单-返回==" + ajax);
        return ajax;
//        HighWorkApproveSheet highWorkApproveSheet1 = new HighWorkApproveSheet();
//        String json = JSON.toJSONString(highWorkApproveSheet1, JSONWriter.Feature.WriteNulls);
//        log.info("json = " + json);
//        return AjaxResult.success("新增成功");
    }

    @PostMapping(value = "/uptHighWorkApproveSheet")
    public AjaxResult uptHighWorkApproveSheet(@RequestBody HighWorkApproveSheet highWorkApproveSheet) {
        log.info(">> 修改高空作业审批单-入参 ==" + JSON.toJSONString(highWorkApproveSheet));
        AjaxResult ajax = highWorkApproveSheetService.uptHighWorkApproveSheet(highWorkApproveSheet);
        log.info(">> 修改高空作业审批单-返回 ==" + ajax);
        return ajax;
    }

    @PostMapping(value = "/queryHighWorkApproveSheet")
    public PageBean queryHighWorkApproveSheet(
            @RequestParam(required = false, value = "hsCode") String hsCode,
            @RequestParam(required = false, value = "hsDept") String hsDept,
            @RequestParam(required = false, value = "hsState") String hsState,
            @RequestParam(required = false, value = "userId") String userId,
            @RequestParam(required = false, value = "mailType") String mailType,//mailType 1-收件箱 2-发件箱 3-草稿箱
            @RequestParam(value = "pageNum") int pageNum,
            @RequestParam(value = "pageSize") int pageSize) {
        log.info(">> 查询高空作业审批单-入参==" + hsCode + "," + hsDept + "," + hsState + "," + userId + "," + mailType);
        PageBean ajax = highWorkApproveSheetService.queryHighWorkApproveSheetByPage(hsCode, hsDept, hsState, userId, mailType, pageNum, pageSize);//mailType 1-收件箱 2-发件箱 3-草稿箱
        log.info(">> 查询高空作业审批单-返回==" + ajax);
        return ajax;
    }
}
